home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / prog / svgacc20.arj / SVGADEMO.C < prev    next >
C/C++ Source or Header  |  1994-03-11  |  14KB  |  593 lines

  1. /****************************************************************************
  2.      
  3.       'SVGACC' A Super Vga Graphics Library for use with Microsoft and
  4.       Borland C/C++
  5.       Copyright 1993-1994 by Stephen L. Balkum and Daniel A. Sill
  6.  
  7.       GIF and 'Graphics Intechange Format' are trademarks (tm) of
  8.       Compuserve, Incorporated, an H&R Block Company.
  9.  
  10.     **************** UNREGISTERD SHAREWARE VERSION ***********************
  11.     * FOR EVUALATION ONLY. NOT FOR RESALE IN ANY FORM. SOFTWARE WRITTEN  *
  12.     * USING THIS UNREGISTERED SHAREWARE GRAPHICS LIBRARY MAY NOT BY SOLD *
  13.     * OR USED FOR ANY PURPOSE OTHER THAN THE EVUALTION OF THIS LIBRARY.  *
  14.     **********************************************************************
  15.  
  16.     **************** NO WARRANTIES AND NO LIABILITY **********************
  17.     * Stephen L. Balkum and Daniel A. Sill provide no warranties, either *
  18.     * expressed or implied, of merchantability, or fitness, for a        *
  19.     * particular use or purpose of this SOFTWARE and documentation.      *
  20.     * In no event shall Stephen L. Balkum or Daniel A. Sill be held      *
  21.     * liable for any damages resulting from the use or misuse of the     * 
  22.     * SOFTWARE and documentation.                                        *
  23.     **********************************************************************
  24.  
  25.     ************** U.S. GOVERNMENT RESTRICTED RIGHTS *********************
  26.     * Use, duplication, or disclosure of the SOFTWARE and documentation  *
  27.     * by the U.S. Government is subject to the restictions as set forth  *
  28.     * in subparagraph (c)(1)(ii) of the Rights in Technical Data and     *
  29.     * Computer Software cluse at DFARS 252.227-7013.                     *
  30.     * Contractor/manufacturer is Stephen L. Balkum and Daniel A. Sill,   *
  31.     * P.O. Box 7704, Austin, Texas 78713-7704                            *
  32.     **********************************************************************
  33.  
  34.     **********************************************************************
  35.     * By using this SOFTWARE or documentation, you agree to the above    *
  36.     * terms and conditions.                                              *
  37.     **********************************************************************
  38.  
  39.  ***************************************************************************/
  40.     
  41.  
  42. #include <stdio.h>
  43. #include <conio.h>
  44. #include <stdlib.h>
  45. #include <string.h>
  46. #include <math.h>
  47. #include <dos.h>
  48.  
  49. #include "svgacc.h"
  50.  
  51. #include "svgademo.h"
  52.  
  53.  
  54. void main(void) {
  55.  
  56.     int startvideomode;
  57.     int i, max, ky;
  58.     int mjv, mnv, tp;
  59.     int cpu, videomemory;
  60.     int mouse, joystick;
  61.     int res;
  62.     int offset, colr;
  63.     float mypi;
  64.     char dummy;
  65.     char buf[TITLEN];
  66.     char *dumptr;
  67.     
  68.     
  69.     /*
  70.      * Save the starting videomode and set it to mode 3.
  71.      */
  72.     startvideomode = videomodeget();
  73.     restext();
  74.     screenclear();
  75.     
  76.     /*
  77.      * Move the DOS cursor to the top left to start the program and say hello
  78.      */
  79.     screengoto(11,0);
  80.     printf("/*SVGACC.LIB/* A SuperVGA Graphics Library for use with\n");
  81.     screengoto(23,1);
  82.     printf("Microsoft and Borland C/C++\n");
  83.     screengoto(9,2);
  84.     printf("Copyright 1993-1994 by Stephen L. Balkum and Daniel A. Sill\n");
  85.     screengoto(23,11);
  86.     printf("Demonstration/Example Program\n");
  87.     screengoto(0,22);
  88.     printf("press a key to begin the demo...\n");
  89.     getkey();
  90.  
  91.     screenclear();
  92.    
  93.     /*
  94.      * Let's id the processor first as the library requires a 386 or better.
  95.      */
  96.     screengoto(0,0);
  97.     cpu = whichcpu();
  98.     if (cpu < 386) {
  99.         printf("Sorry, this library requires an 80386 or better processor.\n");
  100.         printf("Processor is identified as an 80%d.\n", cpu);
  101.         printf("Demo program will be terminated.\n\n");
  102.         printf("press a key...\n");
  103.         getkey();
  104.         videomodeset(startvideomode);
  105.         exit(0);
  106.     }
  107.  
  108.  
  109.     /*
  110.      * Let's id the video card/chip as the library requires a SuperVGA adapter.
  111.      */
  112.     switch(whichvga()) {
  113.         case ACUMOS:
  114.             sprintf(buf,"Acumos AVGA2/3 SuperVGA");
  115.             break;
  116.         case ATI:
  117.             sprintf(buf,"ATI Technologies 18/28/38/68800 SuperVGA");
  118.             break;
  119.         case AHEADA:
  120.             sprintf(buf,"Ahead V5000 Ver A SuperVGA");
  121.             break;
  122.         case AHEADB:
  123.             sprintf(buf,"Ahead V5000 Ver B SuperVGA");
  124.             break;
  125.         case CHIPSTECH:
  126.             sprintf(buf,"Chips and Technologies 82C450/1/2/3/5/6/7 SuperVGA");
  127.             break;
  128.         case CIRRUS:
  129.             sprintf(buf,"Cirrus Logic CL-GD 5xx,6xx,28xx,54xx,62xx SuperVGA");
  130.             break;
  131.         case EVEREX:
  132.             sprintf(buf,"Everex EV236/6xx Micro Enhancer SuperVGA");
  133.             break;
  134.         case GENOA:
  135.             sprintf(buf,"Genoa 61/62/63/64/6600 SuperVGA");
  136.             break;
  137.         case NCR:
  138.             sprintf(buf,"NCR 77C21/22/22E/22E+ SuperVGA");
  139.             break;
  140.         case OAKTECH:
  141.             sprintf(buf,"Oak Technologies OTI-037/67/77/87C SuperVGA");
  142.             break;
  143.         case PARADISE:
  144.             sprintf(buf,"Paradise/Western Digital PVGA1A,WD90C00/1x/2x/3x SuperVGA");
  145.             break;
  146.         case REALTEK:
  147.             sprintf(buf,"Realtek RT3106 SuperVGA");
  148.             break;
  149.         case TRIDENT:
  150.             sprintf(buf,"Trident 8800CS,8900B/C/CL/CX,90x0 SuperVGA");
  151.             break;
  152.         case TSENG3:
  153.             sprintf(buf,"Tseng Labs ET3000-AX/BX/BP SuperVGA");
  154.             break;
  155.         case TSENG4:
  156.             sprintf(buf,"Tseng Labs ET4000/W32/W32I SuperVGA");
  157.             break;
  158.         case VESA:
  159.             sprintf(buf,"VESA compatible SuperVGA");
  160.             break;
  161.         case VIDEO7:
  162.             sprintf(buf,"Video 7 HT-208/16 SuperVGA");
  163.             break;
  164.         case AVANCE:
  165.             sprintf(buf,"Avance Logic AL2101 SuperVGA");
  166.             break;
  167.         case MXIC:
  168.             sprintf(buf,"MXIC MX68000/10 SuperVGA");
  169.             break;
  170.         case PRIMUS:
  171.             sprintf(buf,"Primus P2000 SuperVGA");
  172.             break;
  173.         default:
  174.             printf("Microprocessor is identified as an 80%d.\n", cpu);
  175.             printf("Sorry, unable to identify video card or it is not a SuperVGA video adapter.\n");
  176.             printf("Demo program will be terminated.\n\n");
  177.             printf("press a key...\n");
  178.             getkey();
  179.             videomodeset(startvideomode);
  180.             exit(0);
  181.     }
  182.     printf("Microprocessor is identified as an 80%d.\n", cpu);
  183.     
  184.     fontsystem();
  185.     printf("Video card/chip is identified as %s.\n",&buf);
  186.    
  187.     /*
  188.      * Let's see the how much memory is installed on the super vga adapter.
  189.      */
  190.     videomemory = whichmem();
  191.     if (videomemory < 1) {
  192.         printf("Sorry, unable to identify the amount of installed video memory.\n");
  193.         printf("Demo program will be terminated.\n\n");
  194.         printf("press a key...\n");
  195.         getkey();
  196.         videomodeset(startvideomode);
  197.         exit(0);
  198.     } else
  199.         printf("Installed video memory identified as %dkb.\n", videomemory);
  200.        
  201.     /*
  202.      * Let's tell the user what the highest resolution that the video card
  203.      * and its installed memory card is capable of. The monitor must be able
  204.      * to support those modes too !
  205.      */
  206.     printf("Video card and installed memory is capable of the following resolutions:\n");
  207.     if (videomemory > 1023) {
  208.         printf("    320x200 in 256 colors\n");
  209.         printf("    640x400 in 256 colors\n");
  210.         printf("    640x480 in 256 colors\n");
  211.         printf("    800x600 in 256 colors\n");
  212.         printf("    1024x768 in 256 colors\n");
  213.         max = 4;
  214.     } else if (videomemory > 511) {
  215.         printf("    320x200 in 256 colors\n");
  216.         printf("    640x400 in 256 colors\n");
  217.         printf("    640x480 in 256 colors\n");
  218.         printf("    800x600 in 256 colors\n");
  219.         max = 3;
  220.     } else {
  221.         printf("    320x200 in 256 colors\n");
  222.         printf("    640x400 in 256 colors\n");
  223.         max = 1;
  224.     }
  225.     printf("\nPlease keep in mind that not all monitors support all resolutions.\n\n");
  226.  
  227.     /*
  228.      * Let's look for a mouse. if we find one, tell all about it
  229.      */
  230.     mouse = whichmouse();
  231.     if (mouse > 0) {
  232.         mouseinfo(&mjv, &mnv, &tp, &i);
  233.         switch (tp) {
  234.             case 1:
  235.                 sprintf(buf,"bus mouse");
  236.                 break;
  237.             case 2:
  238.                 sprintf(buf,"serial mouse");
  239.                 break;
  240.             case 3:
  241.                 sprintf(buf,"Inport mouse");
  242.                 break;
  243.             case 4:
  244.                 sprintf(buf,"PS/2 mouuse");
  245.                 break;
  246.             case 5:
  247.                 sprintf(buf,"HP mouse");
  248.                 break;
  249.             default:
  250.                 sprintf(buf,"unknown type");
  251.         }
  252.         printf("Microsoft compatible %s detected with %d buttons on IRQ %d.\n", &buf, mouse, i);
  253.         printf("Software driver version is %d.%d (Microsoft equivalent version).\n\n", mjv, mnv);
  254.  
  255.     } else
  256.         printf("No Microsoft compatible mouse detected.\n\n");
  257.  
  258.     /*
  259.      * Let's look for joysticks
  260.      */
  261.     joystick = whichjoystick();
  262.     switch (joystick) {
  263.         case -1:
  264.             printf("No joystick port detected or no joystick BIOS support present.\n\n");
  265.             break;
  266.         case 0:
  267.             printf("No joystick detected\n\n");
  268.             break;
  269.         case 1:
  270.             printf("Joystick A is present and available.\n\n");
  271.             break;
  272.         case 2:
  273.             printf("Joystick B is present and available.\n\n");
  274.             break;
  275.         case 3:
  276.             printf("Both Joystick A and Joystick B are present and available.\n\n");
  277.             break;
  278.     }
  279.     printf("press a key...\n");
  280.     getkey();
  281.  
  282.  
  283.     /*
  284.      * Let's get down to business
  285.      */
  286.     res = 1;
  287.     endit = 0;
  288.     ky=0;
  289.     
  290.     /*
  291.      * Init alternate color palettes
  292.      */
  293.  
  294.     res320();
  295.     palget(orgpal, 0, 255);
  296.     palcopy(orgpal,pal,0,255);
  297.     palcopy(orgpal,pal2,0,255);
  298.     mypi=(float)(8 * atan(1) / 240);
  299.     offset = 16;
  300.     for (colr=0;colr<240;colr++,offset++) {
  301.         pal[offset].r = (char)(32.0 + sin((colr + 0) * mypi) * 31.0);
  302.         pal[offset].g = (char)(32.0 + sin((colr + 80) * mypi) * 31.0);
  303.         pal[offset].b = (char)(32.0 + sin((colr + 160) * mypi) * 31.0);
  304.         pal2[offset].r = (char)(32.0 + sin((colr + 10) * mypi) * 31.0);
  305.         pal2[offset].g = (char)(32.0 + sin((colr + 30) * mypi) * 31.0);
  306.         pal2[offset].b = (char)(32.0 + sin((colr + 50) * mypi) * 31.0);
  307.     }
  308.     restext();
  309.  
  310.     /*
  311.      * Here is the main selector loop
  312.      */
  313.     while (endit == 0) {
  314.         screenclear();
  315.         switch (res) {
  316.             case 1: 
  317.                 sprintf(buf,"320x200x256");
  318.                 break;
  319.             case 2:
  320.                 sprintf(buf,"640x400x256");
  321.                 break;
  322.             case 3:
  323.                 sprintf(buf,"640x480x256");
  324.                 break;
  325.             case 4:
  326.                 sprintf(buf,"800x600x256");
  327.                 break;
  328.             case 5:
  329.                 sprintf(buf,"1024x768x256");
  330.         }
  331.         printf("Please select the demo you would like to see in the %s resolution:\n\n",&buf);
  332.         printf("(0)  Exit This Program\n\n");
  333.         printf("(1)  Demo #1  The Primitive Drawing Routines\n");
  334.         printf("(2)  Demo #2  The Clipping Capabilities\n");
  335.         printf("(3)  Demo #3  The Fill Routines\n");
  336.         printf("(4)  Demo #4  The Palette Routines\n");
  337.         printf("(5)  Demo #5  The Block Routines\n");
  338.         printf("(6)  Demo #6  The Text Routines\n");
  339.         printf("(7)  Demo #7  The Scrolling Routines\n");
  340.         printf("(8)  Demo #8  The GIF (tm) Routines\n");
  341.         printf("(9)  Demo #9  The Mouse Routines\n");
  342.         printf("(10) Demo #10 The Joystick Routines\n");
  343.         printf("(11) Demo #11 The Two Dimensional Routines\n");
  344.         printf("(12) Demo #12 The Three Dimensional Routines\n");
  345.         printf("(13) The Grand Tour of All Demos\n\n");
  346.         printf("(14) Use 320x200 in 256 colors\n");
  347.         printf("(15) Use 640x400 in 256 colors\n");
  348.         max = 14;
  349.         if (videomemory > 511) {
  350.             printf("(16) Use 640x480 in 256 colors\n");
  351.             printf("(17) Use 800x600 in 256 colors\n");
  352.             max = 17;
  353.         } 
  354.         if (videomemory > 1023) {
  355.             printf("(18) Use 1024x768 in 256 colors\n");
  356.             max = 18;
  357.         }
  358.         
  359.         printf("\nYour Choice: ");
  360.         for (i=0;i<3;i++) {
  361.             dummy = (char)getch();
  362.             switch (dummy) {
  363.                 case 13:
  364.                     if (i == 0)
  365.                         i--;
  366.                     else {
  367.                         buf[i]='\0';
  368.                         i=2;
  369.                     }
  370.                     break;
  371.                 case 8:
  372.                     i--;
  373.                     if (i > (-1)) {
  374.                         printf("\b \b");
  375.                         i--;
  376.                     }
  377.                     break;
  378.                 default:
  379.                     if ((dummy < '0') || (dummy > '9'))
  380.                         i--;
  381.                     else if (i < 2) {
  382.                         printf("%c",dummy);
  383.                         buf[i] = dummy;
  384.                     } else
  385.                         buf[i] = '\0';
  386.  
  387.             }
  388.         }
  389.         ky=(int)strtol(buf,&dumptr,10);
  390.  
  391.         if (ky > max)
  392.             ky = 99;
  393.     
  394.         if((ky > 0) && (ky < 14))
  395.             switch (res) {
  396.                 case 1:
  397.                     res320();
  398.                     break;
  399.                 case 2:
  400.                     res640l();
  401.                     break;
  402.                 case 3:
  403.                     res640();
  404.                     break;
  405.                 case 4:
  406.                     res800();
  407.                     break;
  408.                 case 5:
  409.                     res1024();
  410.                     break;
  411.             }
  412.         
  413.         switch (ky) {
  414.             case 0:
  415.                 endit = 1;
  416.                 break;
  417.             case 1:
  418.                 doprims();
  419.                 break;
  420.             case 2:
  421.                 doclip();
  422.                 break;
  423.             case 3:
  424.                 dofill();
  425.                 break;
  426.             case 4:
  427.                 dopal();
  428.                 break;
  429.             case 5:
  430.                 doblock();
  431.                 break;
  432.             case 6:
  433.                 dotext();
  434.                 break;
  435.             case 7:
  436.                 doscroll();
  437.                 break;
  438.             case 8:
  439.                 dogif();
  440.                 break;
  441.             case 9:
  442.                 domouse();
  443.                 break;
  444.             case 10:
  445.                 dojoystick();
  446.                 break;
  447.             case 11:
  448.                 do2d();
  449.                 break;
  450.             case 12:
  451.                 do3d();
  452.                 break;
  453.             case 13:
  454.                 doall();
  455.                 break;
  456.             case 14:
  457.                 res = 1;
  458.                 break;
  459.             case 15:
  460.                 res = 2;
  461.                 break;
  462.             case 16:
  463.                 res = 3;
  464.                 break;
  465.             case 17:
  466.                 res = 4;
  467.                 break;
  468.             case 18:
  469.                 res = 5;
  470.                 break;
  471.             default:
  472.                 ;
  473.  
  474.         }
  475.         
  476.         restext();
  477.         
  478.     }
  479.  
  480.     videomodeset(startvideomode);
  481.  
  482. }
  483.  
  484. /**********               
  485.  * GETKEY *
  486.  **********/
  487.  
  488. char getkey(void)
  489. {
  490.     char ret;
  491.     beep();
  492.     ret = (char)getch();
  493.     if ( (ret == 'Q') || (ret == 'q') )
  494.         endit = 1;
  495.     if (ret == 'Q')
  496.         ret = 'q';
  497.     if (ret == 'S')
  498.         ret = 's';
  499.     
  500.     return(ret);
  501. }
  502.  
  503.  
  504. /*********
  505.  * DOALL *
  506.  *********/
  507.  
  508. void doall(void)
  509. {
  510.     if(doprims()=='q')
  511.         return;
  512.     if(doclip()=='q')
  513.         return;
  514.     if(dofill()=='q')
  515.         return;
  516.     if(dopal()=='q')
  517.         return;
  518.     if(doblock()=='q')
  519.         return;
  520.     if(dotext()=='q')
  521.         return;
  522.     if(doscroll()=='q')
  523.         return;
  524.     if(dogif()=='q')
  525.         return;
  526.     if(domouse()=='q')
  527.         return;
  528.     if(dojoystick()=='q')
  529.         return;
  530.     if(do2d()=='q')
  531.         return;
  532.     if(do3d()=='q')
  533.         return;
  534.  
  535.     return;
  536.  
  537. }
  538.  
  539.  
  540. /***************
  541.  * SCREENCLEAR *
  542.  ***************/
  543.  
  544. void screenclear(void)
  545. {
  546.     union REGS regs;
  547.  
  548.     regs.h.ah = 0x07;
  549.     regs.h.al = 0x00;
  550.     regs.h.ch = 0;
  551.     regs.h.cl = 0;
  552.     regs.h.dh = 24;
  553.     regs.h.dl = 79;
  554.     regs.h.bh = 7;
  555.     int86(0x10, ®s, ®s);
  556.     screengoto(1,1);
  557. }
  558.  
  559.  
  560. /**************
  561.  * SCREENGOTO *
  562.  **************/
  563.  
  564. void screengoto(int x, int y)
  565. {
  566.     union REGS regs;
  567.  
  568.     regs.h.ah = 0x02;
  569.     regs.h.bh = 0;
  570.     regs.h.dh = (unsigned char)y;
  571.     regs.h.dl = (unsigned char)x;
  572.     int86(0x10, ®s, ®s);
  573. }
  574.  
  575. /********
  576.  * BEEP *
  577.  ********/
  578.  
  579. void beep(void)
  580. {
  581.  
  582.     int cont;
  583.  
  584.     outp(0x43,0xB6);
  585.     outp(0x42,0xA9);
  586.     outp(0x42,0x06);
  587.     cont = inp(0x61);
  588.     outp(0x61,cont | 0x03);
  589.     sdelay(4);
  590.     outp(0x61,cont);
  591.  
  592. }
  593.